package com.ztao.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.apArticle.dto.ArticleDto;
import com.heima.model.common.apArticle.pojos.ApArticleConfig;
import com.heima.model.common.dtos.ResponseResult;
import com.ztao.api.feignarticle.ArticleClientApi;
import com.ztao.service.ApArticleConfigService;
import com.ztao.service.ArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
//
//@RestController
//public class ArticleClient implements ArticleClientApi {
//    @Resource
//    private ArticleService articleService;
//
//    @PostMapping("/api/v1/article/save")
//    @Override
//    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
//        return articleService.saveArticle(dto);
//    }
//}

@RestController
public class ArticleClient implements ArticleClientApi {
    @Resource
    private ArticleService apArticleService;
    @Resource
    private ApArticleConfigService apArticleConfigService;

    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    @GetMapping("/api/v1/article/findArticleConfigByArticleId/{articleId}")
    @Override
    public ResponseResult findArticleConfigByArticleId(@PathVariable("articleId") Long articleId) {
        ApArticleConfig apArticleConfig = apArticleConfigService.getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
        return ResponseResult.okResult(apArticleConfig);
    }

}